package com.devg.file.web.common;

import com.devg.file.web.base.model.ResultModel;
import com.devg.file.web.utils.CommonUtil;
import com.devg.file.web.utils.LocalDateUtil;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = {"/common"})
public class CommonController {

  @RequestMapping(value = "/getDate")
  public ResultModel getDate(@RequestBody Map<String, Object> params) {
    String type = CommonUtil.getMapString(params, "type");
    String startDate = LocalDateUtil.localDateFormat(LocalDate.now(), LocalDateUtil.FORMAT_PATTERN3);
    String endDate = LocalDateUtil.localDateFormat(LocalDate.now(), LocalDateUtil.FORMAT_PATTERN3);
    if (null != type && type.equals("1")) {
      // 查询近7天数据
      startDate = LocalDateUtil.localDateFormat(LocalDate.now().minusDays(7), LocalDateUtil.FORMAT_PATTERN3);
    }
    Map<String, Object> result = new HashMap<>();
    result.put("startDate", startDate);
    result.put("endDate", endDate);
    return ResultModel.newSuccess(result);
  }

}
